/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 13.09.12
 * Time: 20:51
 * To change this template use File | Settings | File Templates.
 */
package fgui.control {
import fgui.GuiComponent;

import fgui.UIGraphicsComponent;

import flash.events.MouseEvent;
import flash.geom.Point;

public class ProgressBar extends GuiComponent {
    private var _value:Number;
    private var _max:Number;
    private var _min:Number;


    private var total:UIGraphicsComponent;
    private var progress:UIGraphicsComponent;
    private var editable:Boolean;

    public function ProgressBar(coordinate:Point, size:Point, editable:Boolean = false) {
        super(coordinate, size);
        this.editable = editable;

        total = new UIGraphicsComponent();
        total.drawRectangle(0xcccccc, 1, new Point(), size);
        addChild(total);

        progress = new UIGraphicsComponent();
        progress.drawRectangle(0x999999, 1, new Point(), size);
        addChild(progress);
    }

    public function onClickProgressBar(event:MouseEvent):void {
        trace("_value = " + _value);
        _value = event.localX / this.getSize().x * (max - min);
        trace("_value = " + _value);
        progress.drawRectangle(
                0x999999,
                0.8,
                new Point(),
                new Point(event.localX, this.getSize().y));
    }

    public function get value():Number {
        return _value;
    }

    public function set value(value:Number):void {
        _value = value;
        progress.drawRectangle(
                0x999999,
                0.8,
                new Point(),
                new Point(_value / (max - min) * this.getSize().x, this.getSize().y));
    }

    public function get max():Number {
        return _max;
    }

    public function set max(value:Number):void {
        _max = value;
    }

    public function get min():Number {
        return _min;
    }

    public function set min(value:Number):void {
        _min = value;
    }
}
}
